if(!sessionStorage.getItem("token")) {
    window.location.href = "/login.html";
}

//2定义方法，获取用户的基本信息
//把用户的token字符串类似于appkey-发送给后台（后台需要知道你是谁）

//把getInfo挂载到window上，以便子网页可以调用该方法
window.getInfo = function() {
    getUinforAPI({},res => {
        console.log(res);
        let {nickname,user_pic,username} = res.data.data;
        if(nickname == null) {
            nickname = username;
        }
        $(".username").html(nickname);
        if(user_pic == null ){
            let firstLetter = nickname[0].toUpperCase();
            $(".avatar").html(firstLetter).css("display","inline-block");
        } else {
            $(".avatar").hide();
            $(".layui-nav-img").attr("src",user_pic).show();
        }
    })
}
getInfo();


//3.点击退出
$("#logout").on("click",function(){
    layer.confirm('确定退出码?', {icon: 3, title:'提示'}, function(index){
        //do something
        layer.close(index);
        sessionStorage.removeItem("token");
        window.location.href = "/login.html"
      });
})